import SETTINGS from "@/settings";
const state = {
  isLogin: null,

  age: null,
  cardIds: null,
  email: null,
  head: null,
  nickName: null,
  phone: null,
  sex: null,
  token: null,
  userId: null,
  userName: null,
  vip: null,
  vipEndTime: null,
  vipScore: null,
  vipStartTime: null,
  vipValidityType: null,
  yzOpenId: null,
};

const mutations = {
  // 更改是否用户登录状态
  TOGGLE_LOGIN_STATUS: (state, { key, value }) => {
    if (state.hasOwnProperty(key)) {
      state[key] = value;
    }
  },
  
  RESET_USER_STATUS: state => {
    Object.keys(state).forEach(item => state[item] = null);
  },
};

const actions = {
  changeUserStatus: ({ commit }, payload) => {
    commit("TOGGLE_LOGIN_STATUS", payload);
  },
  
  reset: ({ commit }) => {
    commit("RESET_USER_STATUS");
    window.sessionStorage.removeItem(SETTINGS.userStore);
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
